package Model;


import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

import map.Map;
import map.CellStatus.CellStatusType;

import org.jgrapht.graph.DefaultWeightedEdge;

public class Edge extends DefaultWeightedEdge {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	List<Point> edgePoints = new ArrayList<Point>();
	public Edge() {
		super();
	}
	public void setPointsList(Point start, Point end, Map map) {
		CellStatusType action = map.getMap()[start.x][start.y].getStatus();
		edgePoints.add(start);
		map.getNextCrossRoadsForPoint().put(edgePoints.get(edgePoints.size()-1), map.getCrossRoadsGraph().getEdgeTarget(this));
		map.getPrecCrossRoadsForPoint().put(edgePoints.get(edgePoints.size()-1), map.getCrossRoadsGraph().getEdgeSource(this));
		System.out.println(start + " to  "  + end + " "+ action + " O_O" + edgePoints.size());
		while(!edgePoints.get(edgePoints.size()-1).equals(end)){
			Point curr = edgePoints.get(edgePoints.size()-1);
			edgePoints.add(getMoveFrom(curr, action));
			map.getNextCrossRoadsForPoint().put(edgePoints.get(edgePoints.size()-1), map.getCrossRoadsGraph().getEdgeTarget(this));
			map.getPrecCrossRoadsForPoint().put(edgePoints.get(edgePoints.size()-1), map.getCrossRoadsGraph().getEdgeSource(this));
			
		}
		System.out.println("path from to  " + start + " -> " + end);
		for (Point p : edgePoints) {
			System.out.println("-> " + p);
		}
		System.out.println("finish");
		
	}
	
	private Point getMoveFrom(Point a, CellStatusType action) {
		if (action.equals(CellStatusType.UP))
			return new Point(a.x - 1, a.y);
		if (action.equals(CellStatusType.DOWN))
			return new Point(a.x + 1, a.y);
		if (action.equals(CellStatusType.RIGHT))
			return new Point(a.x, a.y + 1);
		if (action.equals(CellStatusType.LEFT))
			return new Point(a.x, a.y - 1);
		System.out.println("fuuuck");
		return null;
	}
	public List<Point> getEdgePoints() {
		return edgePoints;
	}
	
	

}
